package com.suning.sawp.in.controller;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.intf.assistant.AssistantService;
import com.suning.sawp.intf.assistant.Result;
import com.suning.sawp.po.assistant.Assistant;
import com.suning.sawp.service.util.BaseContants;
/**
 * 
 * 店+小助手<br> 
 * 〈功能详细描述〉
 *
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/adminPage/assistant")
public class AssistantClientController extends DjBaseController{

        private static final Logger LOGGER = LoggerFactory.getLogger(AssistantClientController.class);
        
        @Autowired
        AssistantService assistantService;
        
        /**
         * 
         * 功能描述: 查询店+助手信息<br>
         * 〈功能详细描述〉
         *
         * @return
         * @see [相关类/方法](可选)
         * @since [产品/模块版本](可选)
         */
        @RequestMapping("/queryAssistant.do")
        public MyGsonView queryAssistant(){
            MyGsonView result = createGsonView();
            result.addStaticAttribute("assistant", assistantService.queryAssistant());
            return result;
        }
        
        /**
         * 
         * 功能描述: 设置店+小助手<br>
         * 〈功能详细描述〉
         *
         * @param staffId
         * @return
         * @see [相关类/方法](可选)
         * @since [产品/模块版本](可选)
         */
        @RequestMapping("/setupAssistant.do")
        public MyGsonView setupAssistant(String staffId){
            MyGsonView res = createGsonView();
            if(StringUtils.isBlank(staffId)){
                setErrorMsg(res,ErrorCodeConstants.ERR_0001);
                return res;
            }
            
            Result<Assistant> result = null;
            try {
                result = assistantService.setupAssistant(staffId);
            } catch (Exception e) {
                LOGGER.error("setupAssistant.do error", e);
                setErrorMsg(res,ErrorCodeConstants.ERR_0005);
                return res;
            }
            
            if(result.getSuccessFlg().equals(BaseContants.FAILED)){
                setErrorMsg(res,ErrorCodeConstants.ERR_0005);
                return res;
            }
            res.addStaticAttribute("assistant", result.getData());
            return res;
        }
        
        /**
         * 
         * 功能描述: 批量群发消息<br>
         * 〈功能详细描述〉
         *
         * @param content
         * @param serviceNumId
         * @return
         * @see [相关类/方法](可选)
         * @since [产品/模块版本](可选)
         */
        @RequestMapping("/sendDjSysMsg.do")
        public MyGsonView sendDjSysMsg(String msgContent, String serviceNumId) {
            ReturnMsg<String> retMsg = assistantService.groupSendMsg(msgContent, serviceNumId);
            return setGsonView(retMsg);
        }
        
}
